package com.jcgyl.export.runner;

import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

import org.quartz.impl.StdSchedulerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.jcgyl.export.config.QuartzConfig;

@Order(1)
@Component
public class TaskRunner implements CommandLineRunner {

	@Override
	public void run(String... args) throws Exception {
		System.out.println(">>>>>>>>>>>>>>>任务服务启动执行 ...<<<<<<<<<<<<<");
		try {
			// 创建scheduler
			QuartzConfig.scheduler = StdSchedulerFactory.getDefaultScheduler();
			// 定义一个Trigger
			QuartzConfig.trigger = newTrigger().withIdentity("trigger1", "group1") // 定义name/group
					.startNow()// 一旦加入scheduler，立即生效
					.withSchedule(simpleSchedule() // 使用简单调度器
							.withIntervalInSeconds(1) // 一秒后开始执行
							.withRepeatCount(0))// 只执行一次
					.build();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}